import React from "react"
import {Route,Redirect} from 'react-router-dom'
import {connect} from 'react-redux'
class Protect extends React.Component{
  componentDidMount(){
    this.props.dispatch({
      type:"change_route",
      path:this.props.path
    })
  }
  render(){
    let str = localStorage.getItem('crmUserInfo')
    if(str){
      return <Route {...this.props}></Route>
    }else{
      return <Redirect to='/login'></Redirect>
    }
    
  }
}
Protect = connect(()=>({}),(dispatch)=>({dispatch}))(Protect)
export default Protect